package com.yy.job.console.utils;

import com.yy.job.common.utils.BaseResult;

public class BaseResultUtil<T> {
	
	public static <T> BaseResult<T> success(T returnObj) {
		BaseResult<T> result = new BaseResult<>();
		result.setSuccess(true);
		result.setCode(CommonErrorCode.SUCCESS.getCode());
		result.setMessage(CommonErrorCode.SUCCESS.getErrorMsg());
		result.setResult(returnObj);
		
		return result;
	}

	public static <T> BaseResult<T> fail(CommonErrorCode error, T returnObj, Object... params) {
		BaseResult<T> result = new BaseResult<>();
		result.setSuccess(false);
		result.setCode(error.getCode());
		result.setMessage(error.getErrorMsg(params));
		result.setResult(returnObj);
		return result;
	}

	public static <T> BaseResult<T> fail(String errCode, String errFormat, Object... params) {
		BaseResult<T> result = new BaseResult<>();
		result.setSuccess(false);
		result.setCode(errCode);
		result.setMessage(String.format(errFormat, params));
		return result;
	}

}
